package com.firefighting.util;

import java.awt.Color;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import com.firefighting.pdfEntity.FirstMaintenance;
import com.firefighting.pdfEntity.SecondMaintenance;
import com.firefighting.pdfEntity.TaskItem;
import com.firefighting.pdfEntity.ThirdMaintenance;
import com.firefighting.util.DBUtil;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.Utilities;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.GrayColor;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfFormField;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.RadioCheckField;

public class MaintenanceItem {
	public static String RESULT ;
	private String[][] TableContent = new String[][]{
		{"序号","单项名称","维护保养情况汇总"},
		{"1","消防供电配电","□ 符合"+" □ 不符合"+" □ 无"},{"2","火灾报警系统","□ 符合"+" □ 不符合"+" □ 无"}
		,{"3","电气火灾监控系统","□ 符合"+" □ 不符合"+" □ 无"},{"4","消防供水设施","□ 符合"+" □ 不符合"+" □ 无"}
		,{"5","消火栓（消防炮）\r\n"+"灭火系统","□ 符合"+" □ 不符合"+" □ 无"},{"6","自动喷水灭火系统","□ 符合"+" □ 不符合"+" □ 无"}
		,{"7","泡沫灭火系统","□ 符合"+" □ 不符合"+" □ 无"},{"8","气体灭火系统","□ 符合"+" □ 不符合"+" □ 无"}
		,{"9","机械加压送风系统","□ 符合"+" □ 不符合"+" □ 无"},{"10","机械排烟系统","□ 符合"+" □ 不符合"+" □ 无"}
		,{"11","集中控制应急照明系统\r\n"+"及疏散指示标志","□ 符合"+" □ 不符合"+" □ 无"}
		,{"12","应急广播系统","□ 符合"+" □ 不符合"+" □ 无"}
		,{"13","消防专用电话","□ 符合"+" □ 不符合"+" □ 无"}
		,{"14","防火分隔","□ 符合"+" □ 不符合"+" □ 无"}
		,{"15","消防电梯","□ 符合"+" □ 不符合"+" □ 无"}
		,{"16","细水雾灭火系统","□ 符合"+" □ 不符合"+" □ 无"}
		,{"17","干粉灭火系统","□ 符合"+" □ 不符合"+" □ 无"}
		,{"18","灭火器","□ 符合"+" □ 不符合"+" □ 无"}
		,{"19","其他设施","□ 符合"+" □ 不符合"+" □ 无"}
		,{"20","主要消防设施标识","□ 符合"+" □ 不符合"+" □ 无"}
	};
	public static final String[] PROJECT = { "消防供电配电", "火灾报警系统", "电气火灾监控系统","消防供水设施"};
	public static final String RESOURCE = "resources/js/buttons.js";
	public static final String[] TIME = { "月报", "季报", "年报"};
	 
	public void CreateContent(String filename,String contractid, String end_time,String start_time,String buildingid) throws IOException, DocumentException, SQLException{
		// step 1
		Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        //构建一个PDF文档输出流程
    	OutputStream pdfFileOutputStream = new FileOutputStream(new File(filename));
    	PdfWriter.getInstance(document,pdfFileOutputStream);
       // step 2
//        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
        // step 3
        document.open();
        BaseFont bfChinese = BaseFont.createFont("C:/Windows//Fonts//SIMHEI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);  
        
      //封面第一行
        Font titlefont = new Font(bfChinese, 20, Font.NORMAL);
        Paragraph covertitle = new Paragraph("建 筑 消 防 设 施 维 护 保 养",titlefont);
        covertitle.setAlignment(1);
        covertitle.setSpacingBefore(100);
        covertitle.setSpacingAfter(50);
        document.add(covertitle);

        
        //封面第二行
        Font titlefont2 = new Font(bfChinese, 40, Font.NORMAL);
        Paragraph covertitle2 = new Paragraph("报   告   书",titlefont2);
        covertitle2.setAlignment(1);
        covertitle2.setSpacingBefore(40);
        covertitle2.setSpacingAfter(150);
        document.add(covertitle2);
        
        
        //增加月、季、年
        Font contentfont = new Font(bfChinese, 16, Font.NORMAL);
//        writer.addJavaScript(Utilities.readFileToString(RESOURCE));
//        PdfContentByte canvas = writer.getDirectContent();
//		Rectangle rect;
//        PdfFormField field;
//        PdfFormField radiogroup = PdfFormField.createRadioButton(writer, true);
//        radiogroup.setFieldName("time");
//        RadioCheckField radio;
//        for (int i = 0; i < TIME.length; i++) {
//            rect = new Rectangle(260, 559 - i * 40, 280, 541 - i * 40);
//            radio = new RadioCheckField(writer, rect, null, TIME[i]);
//            radio.setBorderColor(GrayColor.GRAYBLACK);
//            radio.setBackgroundColor(GrayColor.GRAYWHITE);
//            radio.setCheckType(RadioCheckField.TYPE_CHECK);
//            field = radio.getRadioField();
//            radiogroup.addKid(field);
//            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
//                new Phrase(TIME[i], contentfont), 290, 544 - i * 40, 0);
//        }
//        writer.addAnnotation(radiogroup);

		

        
        //增加项目名称    
        Statement stmt = DBUtil.getConnection().createStatement();
        ResultSet rs = stmt.executeQuery("select project_name from contract where ID='"+contractid+"'");
        while(rs.next()){
    	    String str=rs.getString("project_name");
            Paragraph content = new Paragraph("项   目   名   称:"+" ",contentfont);
            Chunk underline = new Chunk(str,contentfont);
            underline.setUnderline(0.1f, -2f);
            content.add(underline);     
            content.setAlignment(0);
            content.setSpacingBefore(100);
            content.setIndentationLeft(90);
            document.add(content);
        }
            
        //增加委托单位
        ResultSet rs1 = stmt.executeQuery("select name from proprietor where id=(select proprietor_id from contract where ID='"+contractid+"')");
        while(rs1.next()) {
    	   
    	    String strname = rs1.getString("name");
            Paragraph content1 = new Paragraph("委   托   单   位:"+" ",contentfont);
            Chunk underline1 = new Chunk(strname,contentfont);
            underline1.setUnderline(0.1f, -2f); //设置下划线厚度
            content1.add(underline1);     
            content1.setAlignment(0);
            content1.setSpacingBefore(20);  //设置行前间距
            content1.setIndentationLeft(90);  //设置缩进
            document.add(content1);
        }
       
        //增加维护保养机构名称
        ResultSet rs2 = stmt.executeQuery("select name from enterprise where id=(select maintenance_enterprise_id from contract where ID=('133'))");
        while(rs2.next()) {
    	   
    	    String strinstitutions = rs2.getString("name");
            Paragraph content = new Paragraph("维护保养机构名称 :"+" ",contentfont);
            Chunk underline = new Chunk(strinstitutions,contentfont);
            underline.setUnderline(0.1f, -2f); //设置下划线厚度
            content.add(underline);     
            content.setAlignment(0);
            content.setSpacingBefore(20);  //设置行前间距
            content.setIndentationLeft(90);  //设置缩进
            document.add(content);
        }
       
        //增加维护保养机构资质
        ResultSet rs3 = stmt.executeQuery("select qualification from enterprise where id=(select maintenance_enterprise_id from contract where ID=('133'))");
        while(rs3.next()) {
    	   
    	    String straptitude = rs3.getString("qualification");
            Paragraph content = new Paragraph("维护保养机构资质 :"+" ",contentfont);
            Chunk underline = new Chunk(straptitude,contentfont);
            underline.setUnderline(0.1f, -2f); //设置下划线厚度
            content.add(underline);     
            content.setAlignment(0);
            content.setSpacingBefore(20);  //设置行前间距
            content.setIndentationLeft(90);  //设置缩进
            document.add(content);
        }
        
        //增加报告日期
        Date d = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String dateNowStr = sdf.format(d);
        Paragraph content = new Paragraph("报   告   日   期:"+" ",contentfont);
        Chunk underline = new Chunk(dateNowStr,contentfont);
        underline.setUnderline(0.1f, -2f); //设置下划线厚度
        content.add(underline);   
        content.setAlignment(0);
        content.setSpacingBefore(20);  //设置行前间距
        content.setIndentationLeft(90);  //设置缩进
        document.add(content);
        
        //附录内容第一行
        document.newPage();
        Font titlefontzwy = new Font(bfChinese, 20, Font.NORMAL);
        Font f8 = new Font(bfChinese, 8, Font.NORMAL);
        
        Paragraph contenttitlezwy = new Paragraph("建筑消防设施维护保养表",titlefontzwy);
        contenttitlezwy.setAlignment(1);
        contenttitlezwy.setSpacingBefore(25);
        contenttitlezwy.setSpacingAfter(15);
        document.add(contenttitlezwy);
        
       
       //增加项目名称
       Font contentfontzwy = new Font(bfChinese, 14, Font.NORMAL);       
       Statement stmtzwy = DBUtil.getConnection().createStatement();
       ResultSet rszwy = stmtzwy.executeQuery("select * from first_maintenance_project as d where d.Id in (select distinct(c.Id) from first_maintenance_project as c ,"
       		+ "second_maintenance_project as a, contract_maintenance_project as b  where a.Id=b.maintenance_id and a.father_id=c.Id and b.contract_id='"+ contractid+"') order by d.Id");
       //select Name from first_maintenance_project  where Id=(select maintenance_id from contract_manitenance_project where contract_id="+ contractid+") order by Id"
       //select a.Name from first_maintenance_project as a, contract_maintenance_project as b  where a.Id=b.maintenance_id and b.contract_id='"+ contractid+"' order by a.Id"
   
      
       ArrayList<FirstMaintenance> firstMaintenance=new ArrayList<FirstMaintenance>();
       try{
    	   while(rszwy.next()){
    	    	 //  get first maintenance project item;
    	    	   FirstMaintenance fm=new FirstMaintenance();
    	    	   String strzwy=rszwy.getString("Name");
    	    	   String firstId=rszwy.getString("Id");
    	           fm.FirstMaintenanceID=firstId;
    	           fm.FisrtName=strzwy;
    	           firstMaintenance.add(fm);
    	       }
       }catch(Exception e){
			e.printStackTrace();
		}
		finally{
			try {
				rszwy.close();
			}
			catch (Exception e) {
				e.printStackTrace();
			}
		}
      
       ArrayList<ArrayList<SecondMaintenance>> secondMaintenancelist=new ArrayList<ArrayList<SecondMaintenance>>();
       for(int o=0;o<firstMaintenance.size();o++){
    	   // get second maintenance project item
    	   ArrayList<SecondMaintenance> secondMaintenance=new ArrayList<SecondMaintenance>();
    	   String firstId=firstMaintenance.get(o).FirstMaintenanceID;
	       ResultSet rszwy1=stmtzwy.executeQuery("select * from second_maintenance_project as a, contract_maintenance_project as b  where a.Id=b.maintenance_id and b.contract_id='"+ contractid+"' and a.father_id='"+firstId+"' order by a.Id");
	       while(rszwy1.next()){
	    	   SecondMaintenance sm=new SecondMaintenance();
	    	   String SecondNameStr=rszwy1.getString("Name");
	    	   sm.fatherid=rszwy1.getString("father_id");
	    	   sm.Id=rszwy1.getString("Id");
	    	   sm.name=SecondNameStr;
	    	   secondMaintenance.add(sm);
	       }
	       secondMaintenancelist.add(secondMaintenance);
       }
       
      ArrayList<ArrayList<ArrayList<ThirdMaintenance>>> thirdMaintenancelistlist=new ArrayList<ArrayList<ArrayList<ThirdMaintenance>>>();
      for(int o=0;o<secondMaintenancelist.size();o++){
    	  ArrayList<ArrayList<ThirdMaintenance>> thirdMaintenancelist=new ArrayList<ArrayList<ThirdMaintenance>>();
    	  for(int p=0;p<secondMaintenancelist.get(o).size();p++){
    		  String secondid=secondMaintenancelist.get(o).get(p).Id;
    		  ArrayList<ThirdMaintenance> thirdMaintenance=new ArrayList<ThirdMaintenance>();
    		  ResultSet rszwy2=stmtzwy.executeQuery("select * from maintenance_test_content where Father_maintenance_id='"+secondid+"'");
        	  while(rszwy2.next()){
        		  ThirdMaintenance tm=new ThirdMaintenance();
        		  tm.father_maintenance_id=rszwy2.getString("Father_maintenance_id");
        		  if(rszwy2.getString("frequency")==null){
        			  tm.frequency="";
        		  }else{
        			  tm.frequency=rszwy2.getString("frequency");
        		  }
        		  tm.serial=rszwy2.getString("serial");
        		  tm.test_name=rszwy2.getString("test_name");
        		  if(rszwy2.getString("test_content")==null){
        			  tm.test_content="";
        		  }else{
        			  tm.test_content=rszwy2.getString("test_content"); 
        		  }
        		  tm.Id=rszwy2.getString("Id");
        		//  System.out.println(tm.test_name);
        		  thirdMaintenance.add(tm);
        	  }
        	  thirdMaintenancelist.add(thirdMaintenance);
    	  }
    	  thirdMaintenancelistlist.add(thirdMaintenancelist);
       }
      
      
      ArrayList<ArrayList<ArrayList<TaskItem>>> taskItemlistlist=new   ArrayList<ArrayList<ArrayList<TaskItem>>>();
      for(int o=0;o<firstMaintenance.size();o++){
    	  ArrayList<ArrayList<TaskItem>> taskItemlist=new  ArrayList<ArrayList<TaskItem>>(); 
    	  for(int p=0;p<secondMaintenancelist.get(o).size();p++){
    		  ArrayList<TaskItem> taskItem=new  ArrayList<TaskItem>(); 
    		  for(int q=0;q<thirdMaintenancelistlist.get(o).get(p).size();q++){
    			  ResultSet rszwy3=stmtzwy.executeQuery("select * from task_item where execute_time<='"+end_time+"' and execute_time>='"
    			      +start_time+"' and maintenance_detail_id='"+thirdMaintenancelistlist.get(o).get(p).get(q).Id+"' and task_id in (select t.id from building as b,task as t where b.contract_id='"
    					  +contractid+"' and t.building_id=b.id)");  
	
	    			  TaskItem ti=new TaskItem();
	    			  ti.execute_time="";
					  ti.judge_result="";
					  ti.faultDescription="";
					  ti.all_details="";
					  ti.result="";
    			  while(rszwy3.next()){  
	    			  if(rszwy3.getString("maintenance_detail_id").equals(thirdMaintenancelistlist.get(o).get(p).get(q).Id)){
	    				  ti.maintenance_third_id=ti.maintenance_third_id+rszwy3.getString("maintenance_detail_id")+"; ";
	    				  ti.execute_time= ti.execute_time+rszwy3.getString("execute_time")+"; ";
	  	    			  ti.faultDescription=ti.faultDescription+rszwy3.getString("fault_description")+"; ";
	  	    			  ti.judge_result=ti.judge_result+rszwy3.getString("judge_result")+"; ";
	  	    			  ti.result=rszwy3.getString("result");
	  	    			  ti.all_details=ti.all_details+"  "+ti.result+"  "+rszwy3.getString("all_details")+"; ";
	  	    			  ti.task_id=ti.task_id+rszwy3.getString("task_id")+"; ";
	  	    			taskItem.add(ti); 
	    			  }else{System.out.println("maintenance_detail_id !equals thirdMaintenancelistlist.k.id");}
    			  }//end while
    			  if(ti.result.equals("")){ti.all_details="无";}
    			  taskItem.add(ti); 
    		  }// end third for 
    		  taskItemlist.add(taskItem);
    	  }// end second for
    	  taskItemlistlist.add(taskItemlist);
      }
      
      int  count=1;
      for(int o=0;o<firstMaintenance.size();o++){
    	  Paragraph contentzwy = new Paragraph(count+"."+firstMaintenance.get(o).FisrtName,contentfontzwy);    //一级维保内容
          contentzwy.setAlignment(0);
          contentzwy.setSpacingBefore(5);
          contentzwy.setSpacingAfter(5);
          contentzwy.setIndentationLeft(5);
          document.add(contentzwy); 
          
          //制作表格
          PdfPTable pdfTable = new PdfPTable(7);
          //设置表格占PDF文档100%宽度
          pdfTable.setWidthPercentage(100);
          //水平方向表格控件左对齐
          pdfTable.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
          //创建一个表格的表头单元格
          PdfPCell pdfTableHeaderCell = new PdfPCell();
          Font tablefont=new Font(bfChinese, 10, Font.NORMAL);       
          pdfTableHeaderCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
          pdfTableHeaderCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
          String[] normalTableContent={"维保项目","维保内容","测试方法和要求","实测记录","判定结果","备注","执行时间"};
          PdfPCell cell ;
          for(int tzwy=0;tzwy<7;tzwy++){
       	   cell = new PdfPCell(new Phrase(normalTableContent[tzwy].toString(),tablefont));
       	   cell.setHorizontalAlignment(cell.ALIGN_CENTER);
       	   cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
       	   cell.setLeading(2,(float) 1.2);
       	   pdfTable.addCell(cell);//+
          } 
          //完成表头信息
          
          PdfPCell pdfTableContentCell = new PdfPCell();
          pdfTableContentCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
       //   pdfTableContentCell.setVerticalAlignment(pdfTableContentCell.ALIGN_CENTER);
          for(int p=0;p<secondMaintenancelist.get(o).size();p++){
        	  PdfPCell CellSecond=new PdfPCell(new Phrase(secondMaintenancelist.get(o).get(p).name,tablefont)) ;
        	  CellSecond.setRowspan(thirdMaintenancelistlist.get(o).get(p).size());
        	  CellSecond.setColspan(1);
        	  CellSecond.setHorizontalAlignment(CellSecond.ALIGN_CENTER);
        	  CellSecond.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        	  CellSecond.setLeading(2,(float) 1.2);
        	
        	  
        	  pdfTable.addCell(CellSecond);
        	  for(int q=0;q<thirdMaintenancelistlist.get(o).get(p).size();q++){
        		  PdfPCell Cellthird=new PdfPCell(new Phrase(thirdMaintenancelistlist.get(o).get(p).get(q).serial+"."+
        	  thirdMaintenancelistlist.get(o).get(p).get(q).test_name,tablefont));
        		  Cellthird.setHorizontalAlignment(Cellthird.ALIGN_CENTER);
        		  Cellthird.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        		  Cellthird.setLeading(2,(float) 1.2);
        		  Cellthird.setPaddingBottom((float)2.5);
        		  
        		  PdfPCell CellDemand=new PdfPCell(new Phrase(thirdMaintenancelistlist.get(o).get(p).get(q).test_content+" "+
        				  thirdMaintenancelistlist.get(o).get(p).get(q).frequency,tablefont));
        		  CellDemand.setHorizontalAlignment(CellDemand.ALIGN_CENTER);
        		  CellDemand.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        		  CellDemand.setLeading(2,(float) 1.2);
        		 
        		  
        		  
        		  PdfPCell Celltestlog=new PdfPCell(new Phrase(taskItemlistlist.get(o).get(p).get(q).all_details,tablefont));
        		  Celltestlog.setHorizontalAlignment(Celltestlog.ALIGN_CENTER);
        		  Celltestlog.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        		  Celltestlog.setLeading(2,(float) 1.2);
        		 
        		  PdfPCell Celljudge=new PdfPCell(new Phrase(taskItemlistlist.get(o).get(p).get(q).judge_result,tablefont)); 
        		  Celljudge.setHorizontalAlignment(Celljudge.ALIGN_CENTER);
        		  Celljudge.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        		  Celljudge.setLeading(2,(float) 1.2);
        		 
        		  PdfPCell CellDescription=new PdfPCell(new Phrase(taskItemlistlist.get(o).get(p).get(q).faultDescription,tablefont));
        		  CellDescription.setHorizontalAlignment(CellDescription.ALIGN_CENTER);
        		  CellDescription.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        		  CellDescription.setLeading(2,(float) 1.2);
        		
        		  PdfPCell CellTime=new PdfPCell(new Phrase(taskItemlistlist.get(o).get(p).get(q).execute_time,tablefont));
        		  CellTime.setHorizontalAlignment(CellTime.ALIGN_CENTER);
        		  CellTime.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        		  CellTime.setLeading(2,(float) 1.2);
        		  
        		  pdfTable.addCell(Cellthird);
        		  pdfTable.addCell(CellDemand);
        		  pdfTable.addCell(Celltestlog);
        		  pdfTable.addCell(Celljudge);
        		  pdfTable.addCell(CellDescription);
        		  pdfTable.addCell(CellTime);
        	  }
          }
          document.add(pdfTable);
          count++;
      }
       document.close();     
	}
	
	
	public static void main(String[] args) throws IOException, DocumentException, SQLException {
		// TODO Auto-generated method stub
		MaintenanceItem mt = new MaintenanceItem();
		RESULT="E:\\pdfFolder/test1.pdf";
		String contractid="123";
		String buildingid="20";
		String end_time;
		String start_time;
		int  type=Integer.valueOf("0");
		
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");    
		switch(type){
		case 0:
			Calendar c = Calendar.getInstance(); 
			 //过去一月
	        c.setTime(new Date());
	        Date e=c.getTime();
	        end_time = format.format(e);
	        c.add(Calendar.MONTH, -1);
	        Date m = c.getTime();
	        start_time = format.format(m);
	        System.out.println("过去一个月："+start_time);
	        System.out.println("time now："+end_time);
	        mt.CreateContent(RESULT,contractid,end_time,start_time,buildingid);
	        break;
		case 1:
			Calendar c1 = Calendar.getInstance(); 
			 //过去一月
	        c1.setTime(new Date());
	        Date e1=c1.getTime();
	        end_time = format.format(e1);
	        c1.add(Calendar.MONTH, -3);
	        Date m1 = c1.getTime();
	        start_time = format.format(m1);
	        System.out.println("过去3个月："+start_time);
	        System.out.println("time now："+end_time);
	        mt.CreateContent(RESULT,contractid,end_time,start_time,buildingid);
	        break;
		case 2:
			Calendar c2 = Calendar.getInstance(); 
			 //过去一月
	        c2.setTime(new Date());
	        Date e2=c2.getTime();
	        end_time = format.format(e2);
	        c2.add(Calendar.YEAR, -1);
	        Date m2 = c2.getTime();
	        start_time = format.format(m2);
	        System.out.println("过去一年："+start_time);
	        System.out.println("time now："+end_time);
	        mt.CreateContent(RESULT,contractid,end_time,start_time,buildingid);
	        break;
		default:
            System.out.println("undefined number");
            break;
		}
		
		//mt.CreateContent(RESULT,contractid,end_time,start_time,buildingid);
	}
}
